<!--/*
Copyright 2012 Takashi Yokoyama

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

	http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/-->
<!DOCTYPE html>
<html ng-app>
<head>
	<meta charset="utf-8" />
	<title>売掛金登録</title>
	<link rel="stylesheet" href="style.css"></link>
	<script src="/js/angular-1.0.1.min.js"></script>
	<script>
		function Controller($scope, $http, $templateCache) {
			$scope.items = [];

			$scope.addList = function() {
				var item = {
					 ViewDate: $scope.date
					,Name: $scope.name
					,Detail: $scope.itemname
					,Proceed: $scope.proceed
					,MoneyIn: $scope.moneyin
					,Balance: ($scope.proceed - $scope.moneyin)
				};

				$http({method: 'POST', url: '/addproceed', data: item})
					.success(function (data, status) {
						$scope.items.push(item);
					})
					.error(function (data, status) {

					});
			}

			$http({method: 'GET', url: '/proceeddata', cache: $templateCache})
				.success(function(data, status) {
					console.log(data);
					for(var i = 0; i < data.length; i++) {
						$scope.items.push(data[i]);
					}
				})
				.error(function(data, status) {
					console.log("error");
					console.log(data);
					console.log(status);
				});
		}
	</script>
</head>
<body>
	<nav>
		<ul>
			<li><a href="/">トップにもどる</a></li>
		</ul>
	</nav>
	売掛登録
	<article id="contents" ng-controller="Controller">
		<table class="list">
			<tr>
				<th>登録日</th>
				<th>取引先</th>
				<th>品名</th>
				<th>売上金額</th>
				<th>受入金額</th>
				<th>差引残高</th>
				<th>登録／編集</th>
			</tr>
			<tr ng-repeat="item in items">
				<td>{{item.ViewDate}}</td>
				<td>{{item.Name}}</td>
				<td>{{item.Detail}}</td>
				<td>{{item.Proceed}}</td>
				<td>{{item.MoneyIn}}</td>
				<td>{{item.Balance}}</td>
				<td>
					<input type="button" id="bookeditbtn" value="編集" />
					<input type="hidden" id="updatekey" value="{{item.Id}}" />
				</td>
			</tr>
		</table>
		<form>
			<input class="date" type="date" id="datepicker" ng-model="date" placeholder="yyyy-MM-dd" />
			<input type="text" name="name" id="name" ng-model="name" placeholder="取引先"/></td>
			<input type="text" name="itemname" id="itemname" ng-model="itemname" placeholder="品名"/>
			<input class="number" type="number" id="proceeds" ng-model="proceed" placeholder="売上金額"/>
			<input class="number" type="number" id="moneyin" ng-model="moneyin" placeholder="受入金額"/>
			<div>{{proceed - moneyin}}</div>
			<input type="button" id="inputbtn" value="登録"  ng-click="addList()"/>
		</form>

	</article>
</body>
</html>
